﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace WhatCatch.Core2.Repository
{
    public class DB
    {
        static List<Site> listSite = new List<Site>();
        static List<SiteConfig> listSiteConfig = new List<SiteConfig>();

        static DB()
        {
            listSite.Add(new Site
            {
                ID = 1,
                Name = "test",
                Url = "",
                Status = 1,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
            });
            listSite.Add(new Site
            {
                ID = 2,
                Name = "七猫站",
                Url = "",
                Status = 1,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
            });
            listSiteConfig.Add(new SiteConfig
            {
                ID = 1,
                SiteId = 1,
                ListXPath = "",
                ListItemXPath = "//div[@class='list']/div[@class='list-li']",
                ListItemUrlXPath = "",
                PageXPath = "",
                PageItemXPath = "//div[@class='page']/a",
                PageItemUrlXPath = "",
                DetailXPath = "",
                DetailTitleXPath = "//div[@class='detail-title']",
            });
            listSiteConfig.Add(new SiteConfig
            {
                ID = 2,
                SiteId = 2,
                ListXPath = "",
                ListItemXPath = "//div[@class='article-li-title']",
                ListItemUrlXPath = "",
                PageXPath = "",
                PageItemXPath = "//div[@class='article-page']/a",
                PageItemUrlXPath = "",
                DetailXPath = "",
                DetailTitleXPath = "//div[@class='article-title']",
            });
        }

        public static Site GetSite(long id)
        {
            var model = listSite.SingleOrDefault(p => p.ID == id);
            return model;
        }
        public static SiteConfig GetSiteConfig(long id)
        {
            var model = listSiteConfig.SingleOrDefault(p => p.SiteId == id);
            return model;
        }
    }

    public class Site
    {
        public long ID { get; set; }
        public string Name { get; set; }
        public string Url { get; set; }
        public int Status { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime UpdateTime { get; set; }
    }

    public class SiteConfig
    {
        public long ID { get; set; }
        public long SiteId { get; set; }
        /// <summary>
        /// 列表位置xpath
        /// </summary>
        public string ListXPath { get; set; }
        /// <summary>
        /// 列表项xpath
        /// </summary>
        public string ListItemXPath { get; set; }
        /// <summary>
        /// 列表项url位置xpath
        /// </summary>
        public string ListItemUrlXPath { get; set; }
        /// <summary>
        /// 分页位置xpath
        /// </summary>
        public string PageXPath { get; set; }
        /// <summary>
        /// 分页项xpath
        /// </summary>
        public string PageItemXPath { get; set; }
        /// <summary>
        /// 分页项url位置xpath
        /// </summary>
        public string PageItemUrlXPath { get; set; }
        /// <summary>
        /// 明细位置xpath
        /// </summary>
        public string DetailXPath { get; set; }
        /// <summary>
        /// 明细标题xpath
        /// </summary>
        public string DetailTitleXPath { get; set; }
    }
}
